<template>
  <div class="common-layout">
    <el-container>
      <el-aside width="100px"> 积云教育学生管理 </el-aside>
      <el-main>
        <div class="login">
          <h1>欢迎登陆</h1>
          <div>
            <el-input v-model="username" placeholder="请输入账号" clearable />
          </div>
          <div>
            <el-input
              v-model="password"
              type="password"
              placeholder="请输入密码"
              show-password
            />
          </div>
          <div>
            <el-button @click="onLogin" type="primary">登录</el-button>
            <el-button @click="reset">重置</el-button>
          </div>
        </div>
      </el-main>
    </el-container>
  </div>
</template>



<script setup>
import { ref, reactive, toRefs } from "vue";
import { login } from "@/api/api";
import { useStore } from "vuex";
import { useRouter } from "vue-router";
import { ElMessage } from "element-plus";

let store = useStore();
let router = useRouter();
let data = reactive({
  username: "admin",
  password: "123456",
});
let { username, password } = toRefs(data);

let reset = () => {
  data.username = "admin";
  data.password = "123456";
};

let onLogin = () => {
  login(data).then((res) => {
    console.log(res);
    if (res.code == 200) {
      store.commit("saveToken", res);
      router.push("/layout");
      ElMessage({
        message: res.msg,
        type: "success",
      });
    } else {
      ElMessage.error(res.msg);
    }
  });
};
</script>

<style scoped>
.el-aside {
  height: 100vh;
  line-height: 100vh;
  width: 1300px;
  background-color: #1b294f;
  text-align: center;
  color: #ffab00;
  font-size: 60px;
}
.el-main {
  background-color: #353f93;
  display: flex;
}

.login {
  width: 300px;
  height: 350px;
  /* background-color: #fff; */
  margin: auto;
  text-align: center;
  /* line-height: 30px; */
  padding: 0 18px;
  box-sizing: border-box;
}

.login > div {
  margin-bottom: 30px;
}

.login h1 {
  height: 70px;
  line-height: 70px;
  color: #69b2ef;
  font-size: 26px;
}

.login .el-input {
  height: 50px;
}
</style>